//
//  StatusListViewModel.m
//  weibo
//
//  Created by qiuming on 15/12/27.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "StatusListViewModel.h"
#import "StatusViewModel.h"
#import "MJExtension.h"

@interface StatusListViewModel()

@end
@implementation StatusListViewModel

- (void)loadStatusWithCompleted:(void (^)(BOOL))completed {
    
    NSString *token = [UserAccountViewModel sharedUserAccount].userAccount.access_token;
    
    [[NetworkTools sharedNetwordTool]loadStutasWithToken:token finish:^(id result, NSError *error) {
        
        if (error != nil) {
            DDLogError(@"加载数据出错");
            completed(NO);
            return ;
        }
        
        NSArray *array = result[@"statuses"];
        if (array == nil) {
            DDLogError(@"加载数据出错");
            completed(NO);
            return;
        }
        
        NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:array.count];
        for (NSDictionary *dict in array) {
            
            StatusModel *status = [StatusModel mj_objectWithKeyValues:dict];
            
            [arrayM addObject:[StatusViewModel viewModelWithStatus:status]];
        }
        
        [self.statusList addObjectsFromArray:arrayM];
        
        completed(YES);
        DDLogInfo(@"微博数据列表%@", self.statusList);
    }];

}


#pragma mark - 懒加载
- (NSMutableArray *)statusList {
    if (_statusList == nil) {
        _statusList = [[NSMutableArray alloc]init];
    }
    return _statusList;
}
@end
